package com.example.democlient.network.clientpackets;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Message;

import com.example.democlient.MapLocationActivity;
import com.example.democlient.model.Address;
import com.example.democlient.network.packet.ClientPacket;

public class CM_ADDRESS_QUERY_RESPONSE extends ClientPacket {

    private int response;
    private static final Class<? extends Activity> calssz = MapLocationActivity.class;
    public CM_ADDRESS_QUERY_RESPONSE(int opcode) {
        super(opcode);
    }

    @Override
    protected void readImpl() {
    	this.response = readC();
    }

    @Override
    protected void runImpl() {
        switch (response) {
        	case 2:
        		List<Address> list = new ArrayList<Address>();
        		while(getRemainingBytes()!=0){
        			Address address = new Address();
        			address.setId(readD());
        			address.setAddress(readS());
        			address.setXaxis(readDF());
        			address.setYaxis(readDF());
        			address.setDistrictId(readD());
        			list.add(address);
        		}
        		Message msg = new Message();
        		msg.what=2;
        		msg.obj = list;
        		super.getApp().getHander(calssz).sendMessage(msg);
        	default:
        		//super.getApp().getHander(calssz).sendEmptyMessage(response);
                break;
        }
    }
}
